<template>
  <!-- 小组件列表 -->
  <div class="widgets">
    <div class="item" :class="{ hoverBlock: index == 5 }" v-for="(widget, index) in widgets" :key="index"
      @mousedown="mousedown($event, widget)" draggable="true">
      <div class="itemBox">
        <img :src="require('@/assets/icon/' + widget.icon)">
        <div>{{ widget.label }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['widgets'],
  data() {
    return {}
  },
  mounted() { },
  methods: {
    // 鼠标按下事件(原生事件mousedown)
    mousedown(e, widget) {
      this.$emit('onWidgetMouseDown', e, widget)
    }
  },
}
</script>

<style lang="scss" scoped>
.widgets {
  width: 100%;
  height: 100%;
  margin-top: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;

  .item {
    font-size: 14px;
    color: #666;
    padding: 5px;
    margin: 7px;
    border-radius: 6px;
    cursor: pointer;
    position: relative;

    .itemBox {
      width: 55px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    &:hover {
      background: #E6F0FE;
    }

    .tips {
      color: #e6a23c;
      position: absolute;
      right: 0;

      &:hover {
        .tipsCon {
          display: block;
        }
      }

      .tipsCon {
        display: none;
        background: #fff;
        width: 190px;
        padding: 10px;
        border: 1px solid #cdcdcd;
        position: absolute;
        right: 0;
        z-index: 9;
      }
    }
  }

  .hoverBlock {
    display: block;
  }
}
</style>